//
//  YLAdLineFooterView.m
//  YLFinanceService
//
//  Created by she1323 on 2017/8/23.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLAdLineFooterView.h"
#import "DCNumericalScrollView.h"
#import "YLAdLineFooterViewModel.h"
@interface YLAdLineFooterView ()<UIScrollViewDelegate,NoticeViewDelegate>
@property (nonatomic , strong) NSArray *dataArr;/* 滚动 */
@property (strong , nonatomic)DCNumericalScrollView *numericalScrollView;
/* 底部 */
@property (strong , nonatomic)UIView *bottomLineView;

@property (nonatomic, strong) YLAdLineFooterViewModel *viewModel;

@end

@implementation YLAdLineFooterView


- (YLAdLineFooterViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLAdLineFooterViewModel alloc] init];
    }
    return _viewModel;
}

#pragma mark - Intial
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpUI];
        
        [self setUpBase];
        
    }
    return self;
}

- (void)setUpUI
{
    
    if (_numericalScrollView) {
        [_numericalScrollView removeFromSuperview];
        _numericalScrollView = nil;
    }
    
    __weak typeof(self) weakSelf = self;
    [[self.viewModel.aDCommand execute:nil] subscribeNext:^(id  _Nullable x) {
        //初始化
        weakSelf.numericalScrollView = [[DCNumericalScrollView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) andImage:@"notice" andDataTArray:x];
        weakSelf.numericalScrollView.delegate = self;
        //设置定时器多久循环
        weakSelf.numericalScrollView.interval = 5;
        [self addSubview:_numericalScrollView];
        //开始循环
        [weakSelf.numericalScrollView startTimer];
        
        weakSelf.bottomLineView = [[UIView alloc] init];
        [weakSelf addSubview:weakSelf.bottomLineView];
        weakSelf.bottomLineView.frame = CGRectMake(0, self.frame.size.height - 8, self.frame.size.width, 8);
        
    }];
    
    
    
}

- (void)setUpBase
{
    self.backgroundColor = [UIColor whiteColor];
}

+ (NSString *)footerID
{
    return @"YLAdLineFooterView";
}

#pragma mark - Setter Getter Methods
#pragma mark - 滚动条点击事件
- (void)noticeViewSelectNoticeActionAtIndex:(NSInteger)index{
    
    if (self.clickBlock) {
        self.clickBlock();
    }
    
    NSLog(@"点击了第%zd头条滚动条",index);
}

@end
